In a universal hardware system and a matching operating system thereof, task scheduling is usually performed according to a time division principle. A scheduling algorithm emphasizes task fairness, and tries to let different tasks fairly occupy computing resources of a central processing unit (CPU) in turn. However, in reality, there is a specific real-time requirement on many applications, that is, it is required to fulfill a task within a specified time period, and respond to and process an external event that occurs randomly. For such applications, it is difficult for a common software and hardware scheduling algorithm that emphasizes task fairness to meet the requirement, and a task scheduling algorithm ensuring real-time quality must be used.
The prior art has the following technical solutions to solve the real-time quality problem.
A least laxity first (LLF) algorithm is used, where the laxity refers to a remaining idle time after a task is completed. Assuming that at a moment t, an execution time of a remaining part of a task is X and a deadline (absolute) of the task is D, an idle time (laxity) of the task is L=D−t−X. In the LLF algorithm, a priority of a task depends on the laxity. A smaller laxity indicates a higher priority. If tasks have a same laxity, a task whose deadline is earlier has a higher priority and is executed first. In addition, a task can be scheduled only when the laxity is greater than or equal to 0; otherwise, the task is terminated.
However, in the LLF algorithm, when a laxity value is calculated, D and t can be accurately obtained, but it is difficult to accurately estimate a remaining execution time of a task. In addition, because different hardware platforms have different configurations, running periods of time of a same program on different hardware platforms are also different. Therefore, when a task is created, it is difficult to accurately estimate a running time actually required by the task. When the running time actually required by the task is inaccurate, the calculation of a remaining execution time X of the task is also inaccurate in the LLF algorithm, and finally the calculation of a priority is inaccurate, thereby affecting actual efficiency of a real-time task scheduling algorithm.